jQuery(document).ready(function($) {
	 $('textarea.TextBox').autogrow();
	 //发布主题
	 $('#pub_new_post').click(function() {
		var fid = $('#fid').val();
		var subject = $.trim($('#subject').val());
		var message = $.trim($('#message').val());
		var bbs_web_root = $.trim($('#bbs_web_root').val());
		var btn = this;
		var draft = $(btn).attr('name') == 'save_draft' ? 1 : 0;
		if(subject==''){
			$('div.Messages').remove();
			$('<div class="Messages Information"><ul><li>' + '请输入标题！' + '</li></ul></div>').appendTo('body').show();
			return;
		}
		if(message==''){
			$('div.Messages').remove();
			$('<div class="Messages Information"><ul><li>' + '请输入内容！' + '</li></ul></div>').appendTo('body').show();
			return;
		}
		$.ajax({
		type: "POST",
		url:"action/front/do_thread.php?action=new_thread",
			dataType: "",
			data:{'fid': fid,'subject': subject,'message':message,'is_draft':draft},
			success: function(data) {
				if(data=='fail'){
					$.cookie('sysinfo','保存失败!',{ expires: 1, path: '/'});
					//http://localhost/ajaxbbs/index.php?action=viewthread&tid=88063
					location.replace(bbs_web_root);
				}else{
					$.cookie('sysinfo','保存成功!',{ expires: 1, path: '/'});
					location.href=bbs_web_root+'index.php?action=viewthread&tid='+data;
				}
			}
		});
	 });
	//发布回复
	 $('#pub_post').click(function() {
		var fid = $('#fid').val();
		var tid = $('#tid').val();
		var subject = $.trim($('#subject').val());
		var message = $.trim($('#message').val());
		var bbs_web_root = $.trim($('#bbs_web_root').val());
		if(fid=='' || tid=='') {
			$('div.Messages').remove();
			$('<div class="Messages Information"><ul><li>' + '暂不能发表回复' + '</li></ul></div>').appendTo('body').show();
			return false;
		}
		if(subject==''){
			$('div.Messages').remove();
			$('<div class="Messages Information"><ul><li>' + '请输入标题！' + '</li></ul></div>').appendTo('body').show();
			return;
		}
		if(message==''){

			$('div.Messages').remove();
			$('<div class="Messages Information"><ul><li>' + '请输入内容！' + '</li></ul></div>').appendTo('body').show();
			return;
		}
		$.ajax({
		type: "POST",
		url:"action/front/do_post.php?action=new_post",
			dataType: "",
			data:{'fid': fid,'tid':tid,'subject': subject,'message':message},
			success: function(data) {
				location.reload(bbs_web_root+'index.php?action=viewthread&tid='+tid);
			}
		});
	 });
	 
	 // Autosave
	 $('#Form_SaveDraft').livequery(function() {
			var btn = this;
			$('#CommentForm textarea').autosave({ button: btn });
			$('#NewPostForm textarea').autosave({ button: btn });
	 });


});